package com.javabasic.algorithm.leetcode;

/**
 * @Author xiongmin
 * @Description
 * @Date 2021-06-07 21:02
 * @Version 1.0
 **/
public class TargetSum {
    int result;

    public int findTargetSumWays(int[] nums, int target) {
        int size = nums.length;
        result = 0;
        getResult(nums, size, 0, target);
        return result;
    }


    /**
     * 递归解法
     *
     * @param nums
     * @param size
     * @param i
     * @param target
     */
    private void getResult(int[] nums, int size, int i, int target) {
        if (i >= size) {
            if (target == 0) {
                result++;
            }
            return;
        }
        getResult(nums, size, i + 1, target + nums[i]);
        getResult(nums, size, i + 1, target - nums[i]);
    }
}
